// Copyright (c) Microsoft Corporation.  All rights reserved.
using System;
using System.Text;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Microsoft.CSharp;
using System.Collections;
using System.Expressions;
using Microsoft.VisualStudio.DebuggerVisualizers;
using System.Diagnostics;
using System.Runtime.Serialization;

[assembly: DebuggerVisualizer(typeof(ExpressionTreeVisualizer), typeof(ExpressionTreeVisualizerObjectSource), Target = typeof(Expression), Description = "Expression Tree Visualizer")]

public class ExpressionTreeVisualizer : DialogDebuggerVisualizer
{
    private IDialogVisualizerService modalService;

    protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
    {

        modalService = windowService;
        if (modalService == null)
            throw new ApplicationException("This debugger does not support modal visualizers");

        ExprTreeContainer container = (ExprTreeContainer)objectProvider.GetObject();
        TreeBrowser browser = new TreeBrowser();
        browser.Add(container.tree);
        TreeWindow treeForm = new TreeWindow(browser, container.Expr);
        modalService.ShowDialog(treeForm);
    }
}